package com.example.weiba_app;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class friendListAdapter extends SimpleAdapter{

	private int resourceId;
	private Context context;
	private List<? extends Map<String, ?>> data;
	private String[] from;
	private int[] to;
	public friendListAdapter(Context context, List<? extends Map<String, ?>> data,
			int resource, String[] from, int[] to) {
		super(context, data, resource, from, to);
		this.context = context;
		this.data = data;
		this.resourceId = resource;
		
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		RelativeLayout item = (RelativeLayout) View.inflate(context,R.layout.friend_list, null);
		TextView textview = (TextView) item.findViewById(R.id.frilist_textView2);
		Map<String, String> map = (Map<String, String>) data.get(position);
		textview.setText(map.get("sign"));
		textview = (TextView) item.findViewById(R.id.frilist_textView1);
		textview.setText(map.get("displayname"));
	    ImageButton imgbtn = (ImageButton)item.findViewById(R.id.frilist_imageButton);
	    
	    InputStream ins;
		try {
			ins = MainActivity.getAssetManager().open("images/"+map.get("imageButton1"));
			Bitmap bitmap = BitmapFactory.decodeStream(ins);
			imgbtn.setImageBitmap(bitmap);
		} catch (IOException e) {
			e.printStackTrace();
		}
	    

	    
	    imgbtn.setOnClickListener(new OnClickListener()
	    {
	    	public void onClick(View v) 
	    	{
	    		Intent intent = new Intent();
	    		intent.setClass(context,FriInfoActivity.class);
	    		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	    		context.startActivity(intent);
	    		//Activity_review.this.finish();
	    	}
	    });
	    
	    
	    //final Builder bulider = new AlertDialog.Builder(this);
	   
	    return item;
	}

}
